package org.hot100_3;

public class leetcode45 {
    public int jump(int[] nums) {

        int n = nums.length;

        if (n==1){
            return 0;
        }

        int currMaxJump = nums[0];

        int count = 1;

        int nextMaxJump = 0;
        for (int i = 1; i < n; i++) {

            nextMaxJump=Math.max(nextMaxJump,i+nums[i]);

            if (currMaxJump>=n-1){
                return count;
            }

            if (i==currMaxJump){
                count++;
                currMaxJump=nextMaxJump;
                if (currMaxJump>=n-1){
                    return count;
                }
            }
        }

        return count;
    }
}
